package com.welisit.test.init;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

/**
 * @author welisit
 * @create 2022-04-22 16:15
 */
public class MainStart {

    private static Logger log4jLogger = Logger.getLogger(MainStart.class);

    public static void main(String[] args) {
        try {
            initConfig();
            log4jLogger.info("【***********启动定时服务器************】");
            ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/applicationContext-quartz.xml");
            context.registerShutdownHook();
            context.start();
            log4jLogger.info("【***********配置文件加载完成！************】");
        } catch (Exception e) {
            log4jLogger.error("加载配置文件发生异常", e);
        }
    }

    private static void initConfig() {
        FileInputStream fis = null;
        try {
            Properties props = new Properties();
            fis = new FileInputStream("config/log4j.properties");
            props.load(fis);
            PropertyConfigurator.configure(props);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (fis != null)
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
        }
    }
}
